package com.pro.springbootshop.controller;

import com.pro.springbootshop.entity.OtherClasses;
import com.pro.springbootshop.entityExtend.OtherClassesReturn;
import com.pro.springbootshop.mapper.OtherClassesMapper;
import com.pro.springbootshop.service.OtherClassesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class OtherClassesController {
    @Autowired
    OtherClassesService otherClassesService;
    public OtherClassesMapper otherClassesMapper;
    @Autowired
    public void setUserMapper (OtherClassesMapper otherClassesMapper) {
        this.otherClassesMapper = otherClassesMapper;
    }
    @ApiOperation("查询所有副类并返回主类信息")
    @GetMapping("/api/otherClasses")
    public List<OtherClasses> findAllByOther(){
        return otherClassesService.findAllByOther();
    }
    @ApiOperation("商家获取所有副类")
    @GetMapping("/api/otherClasses/{page}/{limit}")
    public OtherClassesReturn getOtherClassesList(@PathVariable(name = "page") Integer page, @PathVariable(name = "limit") Integer limit){
        return otherClassesService.getOtherClassesList(page,limit);
    }
    @ApiOperation("创建一个副类")
    @PostMapping("/api/otherClasses/{mainClassId}/{otherClassName}")
    public String saveOtherClasses(@PathVariable(name = "mainClassId") int mainClassId,@PathVariable(name = "otherClassName") String otherClassName){
        return otherClassesService.saveOtherClasses(mainClassId,otherClassName);
    }
    @ApiOperation("更新一个副类")
    @PostMapping("/api/otherClasses/update")
    public String updateOtherClasses(@RequestBody OtherClasses otherClasses){
        return otherClassesService.updateOtherClasses(otherClasses);
    }
    @ApiOperation("删除一个副类")
    @PostMapping("/api/otherClasses/delete/{otherClassId}")
    public String deleteOtherClasses(@PathVariable(name = "otherClassId") int otherClassId){
        return otherClassesService.deleteOtherClasses(otherClassId);
    }
}
